package com.example.woke;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.woke1.ImageShowActivity;
import com.zhongcai.online.R;
import com.http.HttpMethods;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.PersistentCookieStore;
import com.loopj.android.http.RequestParams;
import com.woke.diyview.RoundProgressBar;
import com.woke.method.Intentnet;
import com.woke.method.MyApp;
import com.wokeMy.view.turui.MyRealNameActivity;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;

import cn.xl.xxl.imagecache.ImageLoader;

public class BorrowinfoActivity extends Activity implements OnClickListener {

	private RoundProgressBar mBar;
	private Intent intent;
	private String id;
	private String orderid = "";
	private TextView mTlili,mTlili1,mTtotalli2,mTtotallili,mTorderno,mTstime,mTdtime,mTtotalmoney;
//	private ProgressBar mProgressBar;
	private boolean badboy;
	private TextView mTok;
	private TextView mTyuqi;
	private String money;
	private MyApp application;
	private boolean sucessbor;
	private int currno;
//	private DialogWidget mDialogWidget;
	private String quota_money;
	private AlertDialog alertDialog;
	private TextView mTforwhy;
	private Dialog dialog;
	private String strtime;//��ǰʱ��
	private String timejls;
	private String user_id;//�µ��˵�id
	private int timejlss;
	private String interest;//��Ϣ
	private String backtime;
	private String creattime;//xiadan shijian
	private TextView mTusername;
	private ImageLoader imageLoader;
	private ImageView mIico;
	private RelativeLayout mRelativ,mRelativ1;
	private String info;//������Ϣ
	private String avatar;//ͷ��url
	private ImageView mImap1;
	private ImageView mImap2;
	private ImageView mImap3;
	private ArrayList<String> imgsUrl = new ArrayList<String>();
	private String quota_pic = "",quota_pic1="",quota_pic2="";//�ϴ���ͼƬ
	private String yuqidatano;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_borrowinfo);

		application = (MyApp) getApplication();
		intent = getIntent();
		id = intent.getStringExtra("id");//����id
		badboy = intent.getBooleanExtra("badboy", false);//trueΪ�Ӹ������Ľ����
		currno = intent.getIntExtra("currno", 101);

		imageLoader = new ImageLoader(this);

		intview();

	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		Intent intent = new Intent();
		intent.setAction("com.woke.personborrowinfoavtivity");
		intent.putExtra("sucessbor", sucessbor);
		intent.putExtra("parent", currno);
		sendBroadcast(intent);
	}

	@Override
	protected void onDestroy() {
		imageLoader.clearCache();
		imageLoader.clearMemoryCache();
		super.onDestroy();
	}


	private void intview() {

		getcurrenttime();

		mRelativ = (RelativeLayout) findViewById(R.id.avboinfo_frame);//��͸��
		mRelativ1 = (RelativeLayout) findViewById(R.id.avboinfo_frame1);//��͸��

		mImap1 = (ImageView) findViewById(R.id.borrow_map1);
		mImap2 = (ImageView) findViewById(R.id.borrow_map2);
		mImap3 = (ImageView) findViewById(R.id.borrow_map3);

		//�Զ���diolag
		 final View layout_log = getLayoutInflater().inflate(R.layout.woke_arlalog, null);
		 layout_log.findViewById(R.id.arlog_text_how).setOnClickListener(this);
         layout_log.findViewById(R.id.arlog_text_dismiss).setOnClickListener(this);
         mBar = (RoundProgressBar) findViewById(R.id.avborrowinfo_bar_progerss);
         mTforwhy = (TextView) findViewById(R.id.avborrowinfo_text_forwhy);
         findViewById(R.id.avborrowinfo_text_howpayback).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				ViewGroup parent = (ViewGroup) layout_log.getParent();
				if(parent != null){
					parent.removeAllViews();
				}

				 dialog = new AlertDialog.Builder(BorrowinfoActivity.this).create();
		         dialog.show();
		         dialog.getWindow().setContentView(layout_log);

			}
		});

		mTlili = (TextView) findViewById(R.id.avborrowinfo_text_lili);
		mTlili1 = (TextView) findViewById(R.id.avborrowinfo_text_llili1);
		mTtotalli2 = (TextView) findViewById(R.id.avborrowinfo_text_totalli2);
		mTtotallili = (TextView) findViewById(R.id.avborrowinfo_text_totallili);
		mTorderno = (TextView) findViewById(R.id.avborrowinfo_text_orderno);
		mTstime = (TextView) findViewById(R.id.avborrowinfo_text_stime);
		mTdtime = (TextView) findViewById(R.id.avborrowinfo_text_dtime);
		mTtotalmoney = (TextView) findViewById(R.id.avborrowinfo_text_totalmoney);
		mTok = (TextView) findViewById(R.id.avborrowinfo_text_ok);
		mTusername = (TextView) findViewById(R.id.avborrowinfo_text_name);
		mIico = (ImageView) findViewById(R.id.avborrowinfo_image_icon);
		badboy = intent.getBooleanExtra("badboy", false);//trueΪ�Ӹ������Ľ����

		if(badboy == true){
			if("13".equals(application.gethavetopay())){
				mTok.setText("还钱");
			}else if("12".equals(application.gethavetopay())){
				mTok.setText("订单完成");
				mTok.setClickable(false);
				mTok.setBackgroundDrawable(getResources().getDrawable(R.drawable.rect_lightgray));
			}else if("10".equals(application.gethavetopay())){
				mTok.setText("等TA还钱");
				mTok.setClickable(false);
				mTok.setBackgroundDrawable(getResources().getDrawable(R.drawable.rect_lightgray));
			}else{
				mTok.setText("不借了");
				mTok.setClickable(true);
				mTok.setBackgroundDrawable(getResources().getDrawable(R.drawable.rect_lightred));
			}
		}else{
			mTok.setText("借给TA");
		}

		mTok.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if(badboy == true){//
					if(application.getDatas_load ()==null){
						Toast.makeText(BorrowinfoActivity.this, "您还未登录！", Toast.LENGTH_SHORT).show();
						return;
					}
					if(application.getDatas_load().getPay_pwd().equals("")){
						Toast.makeText(BorrowinfoActivity.this, "您还未设置支付密码！", Toast.LENGTH_SHORT).show();
						aralogid1("还未设置支付密码","前往设置？",1);
					}else{
						if(application.gethavetopay().equals("13")){
							//��Ǯ
							Intent intent = new Intent(BorrowinfoActivity.this,CheckpaypswActivity.class);
							intent.putExtra("paymoney", quota_money);
							startActivityForResult(intent, 500);
//							mDialogWidget=new DialogWidget(BorrowinfoActivity.this, getDecorViewDialog());
//							mDialogWidget.show();
						}else if(application.gethavetopay().equals("14")){
							//������
							bujiele(id);
//							Intent intent = new Intent(BorrowinfoActivity.this,CheckpaypswActivity.class);
//							startActivityForResult(intent, 500);
//							mDialogWidget=new DialogWidget(BorrowinfoActivity.this, getDecorViewDialog());
//							mDialogWidget.show();
						}
					}
				}else{
					if(null == application.getDatas_load()){
						aralogid("还未登录","前往登录？",1);
					}else if(application.getDatas_load().getUser_no_status().equals("1")){
						aralogid2("还未实名认证","前往认证？",3);
//						Toast.makeText(BorrowinfoActivity.this, "还未实名认证", Toast.LENGTH_SHORT).show();
					}else if(application.getDatas_load().getUser_no_status().equals("2")){
//						aralogid2("还未实名认证","前往认证？",3);
						Toast.makeText(BorrowinfoActivity.this, "实名认证审核中，无操作权限", Toast.LENGTH_SHORT).show();
					}else if(application.getDatas_load().getPay_pwd().equals("")){
						Toast.makeText(BorrowinfoActivity.this, "您还未设置支付密码！", Toast.LENGTH_SHORT).show();
						aralogid1("还未设置支付密码","前往设置？",1);
					}else if(application.getDatas_load().getId().equals(user_id)){
						Toast.makeText(BorrowinfoActivity.this, "自己的订单！", Toast.LENGTH_SHORT).show();
					}else{
						Log.e("借给他", "借给他");
						//�����
//						Intent intent = new Intent();
						intent.setClass(BorrowinfoActivity.this,CheckpaypswActivity.class);
						intent.putExtra("paymoney", quota_money);
						startActivityForResult(intent, 500);
//						mDialogWidget=new DialogWidget(BorrowinfoActivity.this, getDecorViewDialog());
//						mDialogWidget.show();
					}
				}
			}
		});

		mTyuqi = (TextView) findViewById(R.id.avborrowinfo_text_yuqi);
		mTyuqi.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
//				getyuqidata(v);
				showPopupWindow(v,info);
			}
		});



		getdatainfo(id);
		findViewById(R.id.avborrowinfo_image_back).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);

		if(requestCode == 500 && resultCode == 600){
			boolean paypsw = data.getBooleanExtra("paypsw", false);
			if(paypsw == true){
				if(badboy == true){
					if(application.gethavetopay().equals("13")){
						//��Ǯ
						backmoneytohim(id);
					}else if(application.gethavetopay().equals("14")){
//						bujiele(id);
					}
				}else{
					borrowtothey("payPerson");
				}
			}
		}else if(requestCode == 501 && resultCode == 600){

		}

	}

	private void getyuqidata() {
		AsyncHttpClient ahc = new AsyncHttpClient();
        PersistentCookieStore myCookieStore = new PersistentCookieStore(BorrowinfoActivity.this);
        ahc.setCookieStore(myCookieStore);
		RequestParams params = new RequestParams();
		params.put("g", "api");
		params.put("m", "quota");
		params.put("a", "getOverdue");
		params.put("user_id", user_id);
		Log.e("user_id", user_id);
		ahc.get(HttpMethods.BASEURL, params, new JsonHttpResponseHandler(){

			@Override
			public void onSuccess(int statusCode, Header[] headers,
					JSONObject response) {
				super.onSuccess(statusCode, headers, response);
				Log.e("response", "语气"+response);
//				����{"data":{"data":"1"},"time":1458034110,"info":"�û������ڼ�¼��","flag":"success"}
				try {
					String flag = response.getString("flag");
					info = response.getString("info");
					if(flag.equals("success")){
						JSONObject jsonObject = response.getJSONObject("data");
						yuqidatano = jsonObject.getString("data");
						if(info.equals("用户有逾期记录！")){
							mTyuqi.setText("有逾期");
							mTyuqi.setBackgroundDrawable(getResources().getDrawable(R.drawable.rect_lightred));
						}
//						showPopupWindow(v,info);

					}else if(flag.equals("unknow")){
						Toast.makeText(BorrowinfoActivity.this, info, Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}

			@Override
			public void onFailure(int statusCode, Header[] headers,
					String responseString, Throwable throwable) {
				super.onFailure(statusCode, headers, responseString, throwable);
				Toast.makeText(BorrowinfoActivity.this, "数据失败！", Toast.LENGTH_SHORT).show();
//				Log.e("������ǰ�dd", "ʧ��"+responseString);
			}

			@Override
			public void onStart() {
				// TODO Auto-generated method stub
				super.onStart();
//				mProgressBar.setVisibility(View.VISIBLE);
			}

			@Override
			public void onFinish() {
				super.onFinish();
//				mProgressBar.setVisibility(View.GONE);
				Log.e("借给他是吧", "完成");
			}
		});
	}

	public void getcurrenttime() {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
		Date curDate = new Date(System.currentTimeMillis());//��ȡ��ǰʱ��
		strtime = formatter.format(curDate);
		timejls = Intentnet.getTime(strtime);
		timejlss = Integer.parseInt(timejls);
//		Log.e("str", "str"+timejls);
	}

	private void aralogid1(String info,String kll,final int ppp){
		   alertDialog = new AlertDialog.Builder(BorrowinfoActivity.this).
	                setTitle(info).
	                setMessage(kll).
//	                setIcon(R.drawable.ic_launcher). 
	                setPositiveButton("确定", new DialogInterface.OnClickListener() {
	                    @Override
	                    public void onClick(DialogInterface dialog, int which) {
//	                    Intent intent = new Intent();
	                    		intent.setClass(BorrowinfoActivity.this, PswchangeActivity.class);
	                    		intent.putExtra("name", 0);
	                    		startActivity(intent);
	                    		alertDialog.dismiss();
	                    }
	                }).
	                setNegativeButton("取消", new DialogInterface.OnClickListener() {
	                    @Override
	                    public void onClick(DialogInterface dialog, int which) {
	                    	alertDialog.dismiss();
	                        // TODO Auto-generated method stub
	                    }
	                }).create();
	        alertDialog.show();
	}

	private void aralogid2(String info,String kll,final int ppp){
		   alertDialog = new AlertDialog.Builder(BorrowinfoActivity.this).
	                setTitle(info).
	                setMessage(kll).
//	                setIcon(R.drawable.ic_launcher). 
	                setPositiveButton("确定", new DialogInterface.OnClickListener() {
	                    @Override
	                    public void onClick(DialogInterface dialog, int which) {
//	                    Intent intent = new Intent();
	                    		intent.setClass(BorrowinfoActivity.this, MyRealNameActivity.class);
	                    		startActivity(intent);
	                    		alertDialog.dismiss();
	                    }
	                }).
	                setNegativeButton("取消", new DialogInterface.OnClickListener() {
	                    @Override
	                    public void onClick(DialogInterface dialog, int which) {
	                    	alertDialog.dismiss();
	                        // TODO Auto-generated method stub
	                    }
	                }).create();
	        alertDialog.show();
	}


	private void aralogid(String info,String kll,final int ppp){
		   alertDialog = new AlertDialog.Builder(BorrowinfoActivity.this).
	                setTitle(info).
	                setMessage(kll).
//	                setIcon(R.drawable.ic_launcher). 
	                setPositiveButton("确定", new DialogInterface.OnClickListener() {
	                    @Override
	                    public void onClick(DialogInterface dialog, int which) {
//	                    Intent intent = new Intent();
	                    		intent.setClass(BorrowinfoActivity.this, LoadActivity.class);
	                    		startActivity(intent);
	                    		alertDialog.dismiss();
	                    }
	                }).
	                setNegativeButton("取消", new DialogInterface.OnClickListener() {
	                    @Override
	                    public void onClick(DialogInterface dialog, int which) {
	                    	alertDialog.dismiss();
	                        // TODO Auto-generated method stub
	                    }
	                }).create();
	        alertDialog.show();
	}



	 private void showPopupWindow(View view, String info) {

	        // һ���Զ���Ĳ��֣���Ϊ��ʾ������
	        View contentView = getLayoutInflater().inflate(
	                R.layout.pop_window, null);
	        // ���ð�ť�ĵ���¼�
	        final PopupWindow popupWindow = new PopupWindow(contentView,
	                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
	        popupWindow.setTouchable(true);
	        popupWindow.setTouchInterceptor(new OnTouchListener() {

	            @Override
	            public boolean onTouch(View v, MotionEvent event) {
	                return false;
	                // ��������true�Ļ���touch�¼���������
	                // ���غ� PopupWindow��onTouchEvent�������ã��������ⲿ�����޷�dismiss
	            }
	        });
	        ImageView mIyuicon = (ImageView) contentView.findViewById(R.id.yuqi2);
	        TextView mTyutext = (TextView) contentView.findViewById(R.id.yuqi1);
	        if(info.equals("用户有逾期记录！")){
	        	mIyuicon.setImageDrawable(getResources().getDrawable(R.drawable.avborrowinfo_image_yuqi));
	        	mTyutext.setText("用户有"+yuqidatano+"笔逾期记录");
	        	 popupWindow.setBackgroundDrawable(getResources().getDrawable(
	 	                R.drawable.avborrowinfo_image_yuqi));
	        }else{
	        	mIyuicon.setImageDrawable(getResources().getDrawable(R.drawable.avborrowinfo_image_noyuqi));
	        	mTyutext.setText(info);
	        	 popupWindow.setBackgroundDrawable(getResources().getDrawable(
	 	                R.drawable.avborrowinfo_image_noyuqi));
	        }
	        // �������PopupWindow�ı����������ǵ���ⲿ������Back���޷�dismiss����
	        // �Ҿ���������API��һ��bug
	        contentView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
	        int popupWidth = contentView.getMeasuredWidth();
	        int popupHeight =  contentView.getMeasuredHeight();
	        int[] location = new int[2];

	        view.getLocationOnScreen(location);
	        popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, (location[0]+view.getWidth()/2)-popupWidth/2,
	        		location[1]-popupHeight);
	    }

	 private void bujiele(String id) {
			AsyncHttpClient ahc = new AsyncHttpClient();
	        PersistentCookieStore myCookieStore = new PersistentCookieStore(BorrowinfoActivity.this);
	        ahc.setCookieStore(myCookieStore);
			RequestParams params = new RequestParams();
			params.put("g", "api");
			params.put("m", "quota");
			params.put("a", "delPerson");
			params.put("quota_id", id);
			ahc.get(HttpMethods.BASEURL, params, new JsonHttpResponseHandler(){
				@Override
				public void onSuccess(int statusCode, Header[] headers,
						JSONObject response) {
					super.onSuccess(statusCode, headers, response);
//					Log.e("������ǰ�dd", ""+response);
					try {
						String flag = response.getString("flag");
						if(flag.equals("success")){
							application.sethavetopay("");
							Toast.makeText(BorrowinfoActivity.this, "取消成功！", Toast.LENGTH_SHORT).show();
							finish();
						}else if(flag.equals("unknow")){
							String info = response.getString("info");
							Toast.makeText(BorrowinfoActivity.this, info, Toast.LENGTH_SHORT).show();
						}
					} catch (JSONException e) {
						e.printStackTrace();
					}
				}

				@Override
				public void onFailure(int statusCode, Header[] headers,
						String responseString, Throwable throwable) {
					super.onFailure(statusCode, headers, responseString, throwable);
					Toast.makeText(BorrowinfoActivity.this, "数据失败！", Toast.LENGTH_SHORT).show();
//					Log.e("������ǰ�dd", "ʧ��"+responseString);
				}

				@Override
				public void onStart() {
					// TODO Auto-generated method stub
					super.onStart();
					mRelativ1.setVisibility(View.VISIBLE);
				}

				@Override
				public void onFinish() {
					super.onFinish();
					mRelativ1.setVisibility(View.GONE);
//					Log.e("������ǰ�", "���");
				}
			});
		}

	 private void backmoneytohim(String id) {
			AsyncHttpClient ahc = new AsyncHttpClient();
	        PersistentCookieStore myCookieStore = new PersistentCookieStore(BorrowinfoActivity.this);
	        ahc.setCookieStore(myCookieStore);
			RequestParams params = new RequestParams();
			params.put("g", "api");
			params.put("m", "quota");
			params.put("a", "repay");
		 if(application.getDatas_load ()!=null){
			params.put("user_id", application.getDatas_load().getId());
		 }
			params.put("quota_id", id);
			ahc.get(HttpMethods.BASEURL, params, new JsonHttpResponseHandler(){
				@Override
				public void onSuccess(int statusCode, Header[] headers,
						JSONObject response) {
					super.onSuccess(statusCode, headers, response);
//					Log.e("������ǰ�dd", ""+response);
					try {
						String flag = response.getString("flag");
						if(flag.equals("success")){
							application.sethavetopay("");
							Toast.makeText(BorrowinfoActivity.this, "还款成功！", Toast.LENGTH_SHORT).show();
							finish();
						}else if(flag.equals("unknow")){
							String info = response.getString("info");
							Toast.makeText(BorrowinfoActivity.this, info, Toast.LENGTH_SHORT).show();
						}
					} catch (JSONException e) {
						e.printStackTrace();
					}
				}

				@Override
				public void onFailure(int statusCode, Header[] headers,
						String responseString, Throwable throwable) {
					super.onFailure(statusCode, headers, responseString, throwable);
					Toast.makeText(BorrowinfoActivity.this, "数据失败！", Toast.LENGTH_SHORT).show();
//					Log.e("������ǰ�dd", "ʧ��"+responseString);
				}

				@Override
				public void onStart() {
					// TODO Auto-generated method stub
					super.onStart();
					mRelativ1.setVisibility(View.VISIBLE);
				}

				@Override
				public void onFinish() {
					super.onFinish();
					mRelativ1.setVisibility(View.GONE);
//					Log.e("������ǰ�", "���");
				}
			});
		}

	private void borrowtothey(String ersdson) {
		AsyncHttpClient ahc = new AsyncHttpClient();
        PersistentCookieStore myCookieStore = new PersistentCookieStore(BorrowinfoActivity.this);
        ahc.setCookieStore(myCookieStore);
		RequestParams params = new RequestParams();
		params.put("g", "api");
		params.put("m", "quota");
		params.put("a", ersdson);
		params.put("quota_id", orderid);
		params.put("money", money);
		params.put("receiver_type", "5");
		params.put("title", "成功借款");
		params.put("content", "借款成功");
		params.put("receiver_value", ""+application.getregid());
//		Log.e("application.getregid()", ""+application.getregid());
		ahc.get(HttpMethods.BASEURL, params, new JsonHttpResponseHandler(){
			@Override
			public void onSuccess(int statusCode, Header[] headers,
					JSONObject response) {
				super.onSuccess(statusCode, headers, response);
				Log.e("借给他是吧dd", ""+response);
				try {
					String flag = response.getString("flag");
					if(flag.equals("success")){
						if(badboy == false){
							sucessbor = true;
							Toast.makeText(BorrowinfoActivity.this, "�����ɹ���", Toast.LENGTH_SHORT).show();
							application.sethavetopay("");
							ArrayList<String> listsuc = new ArrayList<String>();
							//����Ϣ����Ϣ�ܶ����ʱ�䡢����ʱ�䡢����id����;������ˡ�ͷ��
							listsuc.add(quota_money);listsuc.add(mTlili1.getText().toString());listsuc.add(mTtotalli2.getText().toString());
							listsuc.add(creattime);listsuc.add(backtime);listsuc.add(id);listsuc.add(mTforwhy.getText().toString());
							listsuc.add(mTusername.getText().toString());listsuc.add("http://"+avatar);
							intent.setClass(BorrowinfoActivity.this, BorrowsucessActivity.class);
							intent.putExtra("listsuc", listsuc);
							startActivity(intent);
							finish();
						}
//						else{
//							sucessbor = true;
//						}
					}else if(flag.equals("unknow")){
						String info = response.getString("info");
						Toast.makeText(BorrowinfoActivity.this, info, Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}

			@Override
			public void onFailure(int statusCode, Header[] headers,
					String responseString, Throwable throwable) {
				super.onFailure(statusCode, headers, responseString, throwable);
				Toast.makeText(BorrowinfoActivity.this, "数据失败！", Toast.LENGTH_SHORT).show();
				Log.e("借给他是吧dd", "失败"+responseString);
			}

			@Override
			public void onStart() {
				// TODO Auto-generated method stub
				super.onStart();
				mRelativ1.setVisibility(View.VISIBLE);
			}

			@Override
			public void onFinish() {
				super.onFinish();
				mRelativ1.setVisibility(View.GONE);
				Log.e("借给他是吧", "完成");
			}
		});
	}

	private void getdatainfo(String id) {
		AsyncHttpClient ahc = new AsyncHttpClient();
      PersistentCookieStore myCookieStore = new PersistentCookieStore(BorrowinfoActivity.this);
      ahc.setCookieStore(myCookieStore);
		RequestParams params = new RequestParams();
		params.put("g", "api");
		params.put("m", "quota");
		params.put("a", "detailPerson");
		params.put("quota_id", id);
//		Log.e("i99999", id);
		ahc.get(HttpMethods.BASEURL, params, new JsonHttpResponseHandler(){
			@Override
			public void onSuccess(int statusCode, Header[] headers,
					JSONObject response) {
				super.onSuccess(statusCode, headers, response);
//				Log.e("fanhui����", ""+response);
				try {
					String flag = response.getString("flag");
					if(flag.equals("success")){
						JSONObject jsonObject = response.getJSONObject("data");
						JSONObject arra = jsonObject.getJSONObject("data");
							money = arra.getString("money");
							mTtotallili.setText(money+"元");
							mTtotalli2.setText(money+"元");
							String status = arra.getString("status");
							String total_date = arra.getString("total_date");
							float total = Float.parseFloat(total_date);//�ܵ���Ч����
//							int total = Integer.parseInt(total_date);
							String repay_date = arra.getString("repay_date");
							backtime = Intentnet.getStrTime(repay_date);
							mTdtime.setText(backtime);
							String mark = arra.getString("mark");
							String type = arra.getString("type");
							quota_pic = arra.getString("quota_pic");
							quota_pic1 = arra.getString("quota_pic1");
							quota_pic2 = arra.getString("quota_pic2");

							if(!quota_pic.equals("")){
								imgsUrl.add("http://"+quota_pic);
								imageLoader.DisplayImage("http://"+quota_pic, mImap1, false, false, true,0);
							}
							if(!quota_pic1.equals("")){
								imgsUrl.add("http://"+quota_pic1);
								imageLoader.DisplayImage("http://"+quota_pic1, mImap2, false, false, true,0);
							}
							if(!quota_pic2.equals("")){
								imgsUrl.add("http://"+quota_pic2);
								imageLoader.DisplayImage("http://"+quota_pic2, mImap3, false, false, true,0);
							}
							if(!quota_pic.equals("")){
								mImap1.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View v) {

										Intent intent = new Intent(BorrowinfoActivity.this,ImageShowActivity.class);
										intent.putExtra("index", imgsUrl.get(0));
										intent.putExtra("infos", imgsUrl);
										startActivity(intent);

//										intent.setClass(BorrowinfoActivity.this, MapshowActivity.class);
//										intent.putExtra("mapurl", "http://"+quota_pic);
//										intent.putExtra("index", quota_pic);
//										intent.putStringArrayListExtra("infos", imgsUrl);
//										intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//										 startActivity(intent);
									}
								});
							}if(!quota_pic1.equals("")){
								mImap2.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View v) {

										Intent intent = new Intent(BorrowinfoActivity.this,ImageShowActivity.class);
										intent.putExtra("index", imgsUrl.get(1));
										intent.putExtra("infos", imgsUrl);
										startActivity(intent);

//										intent.setClass(BorrowinfoActivity.this, MapshowActivity.class);
//										intent.putExtra("mapurl", "http://"+quota_pic1);
//										startActivity(intent);
									}
								});
							}if(!quota_pic2.equals("")){
								mImap3.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View v) {

										Intent intent = new Intent(BorrowinfoActivity.this,ImageShowActivity.class);
										intent.putExtra("index", imgsUrl.get(2));
										intent.putExtra("infos", imgsUrl);
										startActivity(intent);
//										intent.setClass(BorrowinfoActivity.this, MapshowActivity.class);
//										intent.putExtra("mapurl", "http://"+quota_pic2);
//										 startActivity(intent);
									}
								});
							}

							String creat_date = arra.getString("creat_date");
//							Log.e("creat_date", "$$"+creat_date);
							creattime = Intentnet.getStrTime(creat_date);
							int parseInt = Integer.parseInt(creat_date);
							mTstime.setText(creattime);
							orderid = arra.getString("id");
							mTorderno.setText(orderid);
							String services_fee = arra.getString("services_fee");
							avatar = arra.getString("avatar");
							imageLoader.DisplayImage("http://"+avatar, mIico, false, true, true,0);
							String user_nicename = arra.getString("user_nicename");
							mTusername.setText(user_nicename);
							interest = arra.getString("interest");
							float lili=Float.parseFloat(interest);
							mTlili.setText(""+lili*100+"%");
							mTlili1.setText(""+lili*100+"%");
							String quota_use = arra.getString("quota_use");
							mTforwhy.setText(quota_use);
							user_id = arra.getString("user_id");
							getyuqidata();//��ѯ���ڼ�¼
							quota_money = arra.getString("quota_money");
							mTtotalmoney.setText("￥"+quota_money+"元");
							String exp_date = arra.getString("exp_date");
							float lasttiem = Float.parseFloat(exp_date);//ʣ����Ч����
							int adays = Integer.valueOf(exp_date).intValue();
							float degree = (lasttiem / total)*100;
							String baifenbi = (""+degree);
							int indexOf = baifenbi.indexOf(".");
							String substring = baifenbi.substring(0, indexOf);
							int parseInt2 = Integer.parseInt(substring);
//							Log.e("parseInt2", "222"+parseInt2);
							Random rd = new Random();
							mBar.setProgress(parseInt2,adays);//ȫ���ȶ���
//							mBar.setProgress(nextInt,adays-nextInt);
							String friend = arra.getString("friend");
							String quota_type = arra.getString("quota_type");
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}

			@Override
			public void onStart() {
				// TODO Auto-generated method stub
				super.onStart();
				mRelativ.setVisibility(View.VISIBLE);
			}

			@Override
			public void onFailure(int statusCode, Header[] headers,
					String responseString, Throwable throwable) {
				super.onFailure(statusCode, headers, responseString, throwable);
				Toast.makeText(BorrowinfoActivity.this, "数据失败！", Toast.LENGTH_SHORT).show();
//				Log.e("response", "ʧ��"+responseString);
			}

			@Override
			public void onFinish() {
				super.onFinish();
				mRelativ.setVisibility(View.GONE);
//				Log.e("response", "���");
			}
		});
	}

	@Override
	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.arlog_text_how:
			ArrayList<String> list = new ArrayList<String>();
			list.add("");
			Intent intent = new Intent(BorrowinfoActivity.this,YuqiActivity.class);
			intent.putExtra("list", list);
			startActivity(intent);
//			Toast.makeText(BorrowinfoActivity.this, "��ô����", Toast.LENGTH_SHORT).show();
			break;

		case R.id.arlog_text_dismiss:
			dialog.dismiss();
			break;

		default:
			break;
		}
	}
}
